fix(svelte): Track components without <script>
tags
#5930
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in our Svelte component tracking implementation where Svelte components without a
<script>
tag were not tracked.It adds a function to the preprocessor's
markup
hook that has access to the whole.svelte
component file. In this function we check if there is a script tag and in case there is not, we add an empty<script> </script>
tag to the code. This will later on be picked up by thescript
hook where we inject ourtrackComponent
function call.Furthermore, this PR adds a few tests to check this new behaviour. It's worth mentioning that I added two "higher level" tests that actually use the Svelte compiler's own
preprocess
function to which we pass our preprocessor. This gives us a more close to real-use testing scenario.fixes #5923